<?php

namespace app\admin\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
        'username' => 'require|isMobile',
        'password' => 'require|max:50',
    ];

    protected $message = [
        'username.require' => '手机号不能为空 ',
        'username.max' => '手机格式输入有误',
        'password.require' => '密码不能为空 ',
        'password.max' => '密码不能超过50个字符 ',
    ];

    //验证场景
    protected $scene = [
        //'add'   =>  ['zh_name','field_type'],
        'edit' => ['username'],
    ];

    // 自定义 notPrice 验证规则，正确的价格
    public function notPrice($value)
    {
        return 1 === preg_match('/^\d+(\.\d+)?$/', (string)$value);
    }

    public function isMobile($value)
    {
        return isMobile($value);
    }
}